/********************************************************************************
Title: Data Preparation for Nigeria Sample
		Define time points
		Define variables to use in each index
		Define survey round to use as reference round
********************************************************************************/

loc ref month == 1

*----------------------------------
use "${raw}/nigeria/nigeria_desc", clear
keep id age female ses
tempfile desc
save `desc'


use  "${raw}/nigeria/nigeria.dta", clear
cap drop female
cap drop age
cap drop ses

merge m:1 id using `desc', nogen
*-------------------------------------------------------------------------------
*			0. Formating and Renaming Variables
*-------------------------------------------------------------------------------
keep if !mi(pid)
keep if !mi(date)
isid pid date
tostring hhid, replace

gen month = month(date) - 14 + 12*year(date) - 12*2019
replace month = 4 if month == 5 
tab month

*-------------------------------------------------------------------------------
*			1. Generating Variable Lists
*-------------------------------------------------------------------------------
macro drop  depression
gl depression happiness1 happiness3 happiness4

*-------------------------------------------------------------------------------
*			2. Generating Indices
*-------------------------------------------------------------------------------
foreach g in depression {
	foreach var of varlist $`g' {
	recode `var' (7 8 = .)
	sum `var' if `ref'
	replace `var' = (`var' - `r(mean)')/`r(sd)'
	gen swt_`var' = `var'
	}
}

factor $depression if  `ref', ipf factor(1)
predict ___depression_fw

*-------------------------------------------------------------------------------
*          Unweighted indices
*-------------------------------------------------------------------------------
egen ___depression_nw = rowmean($depression)

*-------------------------------------------------------------------------------
*          Inverse-covariance-weighted indices
*-------------------------------------------------------------------------------
icw_index($depression), gen(___depression_icw)


reg ___depression_nw ses
